package calorie.com.calorie.contact;

import android.content.Context;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;


import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.constant.Constant;
import calorie.com.calorie.request.BaseResponce;
import calorie.com.calorie.request.FirstLoginModifyPwdRequest;
import calorie.com.calorie.request.FirstLoginSendCodeRequest;
import retrofit2.Call;
import retrofit2.Response;

public class FirstLoginModifyPwdContact {
    public static class FisrtLoginModifyPwdPResent  extends BasePresent<IFirstLoginModifyPwdView>{
        public void getSecurityCode(Context context,String phonet){
            ApiService service = ServiceGenerator.createService(ApiService.class);
            FirstLoginSendCodeRequest request=new FirstLoginSendCodeRequest(phonet,"4");
            service.firstLoginSendCode(request).enqueue(new NetCallBack<BaseResponce>() {
                @Override
                public void onSuccess(Call<BaseResponce> call, Response<BaseResponce> response) {
                    if (getView()!=null){
                        getView().getSecurityCode(response);
                    }
                }

                @Override
                public void onFailed() {
                   // ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }

        public void modifyPwd(Context context,String logPwd,String dealPwd,String phone,String code){
            ApiService service = ServiceGenerator.createService(ApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            FirstLoginModifyPwdRequest request=new FirstLoginModifyPwdRequest(Md5Utils.stringToMD5(logPwd),Md5Utils.stringToMD5(dealPwd),phone,code,userId);
            service.firstLoginModifyPwd(request).enqueue(new NetCallBack<BaseResponce>() {
                @Override
                public void onSuccess(Call<BaseResponce> call, Response<BaseResponce> response) {
                    if (getView()!=null){
                        getView().getModifyPwdData(response);
                    }
                }

                @Override
                public void onFailed() {
                   // ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }
    }

    public interface IFirstLoginModifyPwdView extends IBaseView{
        void getSecurityCode(Response<BaseResponce> response);
        void getModifyPwdData(Response<BaseResponce> response);
    }
}
